/**
 * Created by gastrodia on 14-7-16.
 */


var log4js = require('log4js');
var utils = require('./utils/index');

var path = require('path');
var fs = require('fs-extra');
var core = require('./index');

//确定日志目录存在，不存在先创建
var dir = path.join(core.getProjectRoot(),'backend/logs/core');
fs.mkdirsSync(dir)


log4js.configure({
    appenders: [
        {
            type: 'console'
        }, //控制台输出
        {
            type: "dateFile",
            filename: path.join(dir,'log.log'),
            pattern: "_yyyy-MM-dd",
            alwaysIncludePattern: false,
            category: 'normal'
        }//日期文件格式
    ],
    replaceConsole: true,   //替换console.log
    levels:{
        normal: 'INFO'
    }
});

var logger = log4js.getLogger('normal');

logger.add = function(server){
    server.app.use(log4js.connectLogger(logger, {level:'auto', format:':method :url'}));
}

module.exports = logger;
